<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>越近越好 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/_closer_is_better.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/_closer_is_better.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/_closer_is_better.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/_closer_is_better.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="search-in-depth.html">深入搜索</a></span>
»
<span class="breadcrumb-link"><a href="proximity-matching.html">近似匹配</a></span>
»
<span class="breadcrumb-node">越近越好</span>
</div>
<div class="navheader">
<span class="prev">
<a href="_multivalue_fields_2.html">« 多值字段</a>
</span>
<span class="next">
<a href="proximity-relevance.html">使用邻近度提高相关度 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="_closer_is_better"></a>越近越好<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/120_Proximity_Matching/20_Scoring.asciidoc">edit</a>
</h2>
</div></div></div>
<p>鉴于一个短语查询仅仅排除了不包含确切查询短语的文档， 而 <em>邻近查询</em> — 一个
<code class="literal">slop</code> 大于 <code class="literal">0</code>— 的短语查询将查询词条的邻近度考虑到最终相关度 <code class="literal">_score</code> 中。 通过设置一个像 <code class="literal">50</code> 或者 <code class="literal">100</code> 这样的高 <code class="literal">slop</code> 值, 你能够排除单词距离太远的文档， 但是也给予了那些单词临近的的文档更高的分数。</p>
<p>下列对 <code class="literal">quick dog</code> 的邻近查询匹配了同时包含 <code class="literal">quick</code> 和 <code class="literal">dog</code> 的文档， 但是也给了与 quick 和 dog 更加临近的文档更高的分数 ：</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">POST /my_index/my_type/_search
{
   "query": {
      "match_phrase": {
         "title": {
            "query": "quick dog",
            "slop":  50 <a id="CO84-1"></a><i class="conum" data-value="1"></i>
         }
      }
   }
}</pre>
</div>
<div class="sense_widget" data-snippet="snippets/120_Proximity_Matching/20_Scoring.json"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO84-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>注意高 <code class="literal">slop</code> 值。</p>
</td>
</tr>
</table>
</div>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "hits": [
     {
        "_id":      "3",
        "_score":   0.75, <a id="CO85-1"></a><i class="conum" data-value="1"></i>
        "_source": {
           "title": "The quick brown fox jumps over the quick dog"
        }
     },
     {
        "_id":      "2",
        "_score":   0.28347334, <a id="CO85-2"></a><i class="conum" data-value="2"></i>
        "_source": {
           "title": "The quick brown fox jumps over the lazy dog"
        }
     }
  ]
}</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO85-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>分数较高因为 <code class="literal">quick</code> 和 <code class="literal">dog</code> 很接近</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO85-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>分数较低因为 <code class="literal">quick</code> 和 <code class="literal">dog</code> 分开较远</p>
</td>
</tr>
</table>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="_multivalue_fields_2.html">« 多值字段</a>
</span>
<span class="next">
<a href="proximity-relevance.html">使用邻近度提高相关度 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>